<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:th="http://www.thymeleaf.org"
      xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
      layout:decorator="fragments/page">

<head>
    <meta charset="UTF-8"/>
    <title>Title</title>
</head>
<body>

<div th:fragment="pager">

 <!--   <div class="table-pagination">
        <ul class="pagination">
            <li th:class="${datas.size eq 0} ? 'disabled' : ''">
                <a th:if="${not datas.isFirstPage}" th:href="@{${'/contacts'}(page=${datas.pageNum-1},size=${datas.size})}">Previous</a>
                <a th:if="${datas.firstPage}" href="javascript:void(0);">Previous</a>
            </li>

            <li th:each="pageNo : ${#numbers.sequence(0, datas.pages - 1)}" th:class="${datas.pageNum eq pageNo}? 'active' : ''">
                <a th:if="${datas.pageNum  eq pageNo}" href="javascript:void(0);">
                    <span th:text="${pageNo + 1}"></span>
                </a>
                <a th:if="${not (datas.pageNum  eq pageNo)}" th:href="@{${'/contacts'}(page=${pageNo},size=${datas.size})}">
                    <span th:text="${pageNo + 1}"></span>
                </a>

            </li>
            <li th:class="${datas.pageNum + 1 ge datas.pages} ? 'disabled' : ''">
                <a th:if="${not datas.isLastPage}" th:href="@{${'/contacts'}(page=${datas.pageNum+1},size=${datas.size})}">Next</a>
                <a th:if="${datas.lastPage}" href="javascript:void(0);">Next</a>
            </li>
        </ul>
    </div>-->


    <div class="text-right" th:with="baseUrl=${#httpServletRequest.getRequestURL().toString()},pars=${#httpServletRequest.getQueryString() eq null ? '' : new String(#httpServletRequest.getQueryString().getBytes('iso8859-1'), 'UTF-8')}">
        <ul style="margin:0px;" class="pagination" th:with="newPar=${new String(pars eq null ? '' : pars).replace('page='+(datas.pageNum), '')},
                                                curTmpUrl=${baseUrl+'?'+newPar},
                                                curUrl=${curTmpUrl.endsWith('&amp;') ? curTmpUrl.substring(0, curTmpUrl.length()-1):curTmpUrl}" >
            <!--<li th:text="${pars}"></li>-->

            <li><a href="#" th:href="@{${curUrl}(page=1)}">首页</a></li>
            <li th:if="${datas.hasPreviousPage}"><a href="#" th:href="@{${curUrl}(page=${datas.pageNum-1})}">上一页</a></li>

            <!--总页数小于等于5-->
            <div th:if="${(datas.pageNum le 3) and (datas.pageNum gt 0)}" th:remove="tag">
                <div th:each="pg : ${#numbers.sequence(1, 5)}" th:remove="tag">
                        <span th:if="${pg eq datas.pageNum}" th:remove="tag">
                            <li class="active"><span class="current_page line_height" th:text="${pg}"></span></li>
                        </span>
                            <span th:unless="${pg eq datas.pageNum}" th:remove="tag">
                            <li><a href="#" th:href="@{${curUrl}(page=${pg})}" th:text="${pg}"></a></li>
                        </span>
                </div>
            </div>

            <!-- 总数数大于5时 -->
            <div th:if="${datas.pageNum gt 3}" th:remove="tag">
                <li th:if="${datas.pageNum-2 ge 0}"><a href="#" th:href="@{${curUrl}(page=${datas.pageNum}-2)}" th:text="${datas.pageNum-2}"></a></li>
                <li th:if="${datas.pageNum-1 ge 0}"><a href="#" th:href="@{${curUrl}(page=${datas.pageNum}-1)}" th:text="${datas.pageNum-1}"></a></li>
                <li class="active"><span class="current_page line_height" th:text="${datas.pageNum}"></span></li>
                <li th:if="${datas.pageNum+1 le datas.pages}"><a href="#" th:href="@{${curUrl}(page=${datas.pageNum}+1)}" th:text="${datas.pageNum+1}"></a></li>
                <li th:if="${datas.pageNum+2 le datas.pages}"><a href="#" th:href="@{${curUrl}(page=${datas.pageNum}+2)}" th:text="${datas.pageNum+2}"></a></li>
            </div>


            <li th:if="${datas.hasNextPage}"><a href="#" th:href="@{${curUrl}(page=${datas.pageNum+1})}">下一页</a></li>
            <!--<li><a href="#" th:href="@{${curUrl}(page=${datas.pages-1})}">尾页</a></li>-->
            <li><a href="#" th:href="${datas.pages le 0 ? curUrl+'page=0':curUrl+'&amp;page='+(datas.pages)}">尾页</a></li>
            <li><span th:utext="'共'+${datas.pages}+'页 / '+${datas.total}+' 条'"></span></li>
        </ul>
    </div>


</div>

</body>
</html>